package com.awakening.sorting.entity;

/**
 * @Author:AwakeningCode
 * @Date: Created in 8:46 2018\1\17 0017
 */
public class Student implements Comparable<Student>{

    private String name;
    private int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    /**
     * 定义Student的compareTo函数
     * 如果分数相等，则按照名字的字母序排序
     * 如果分数不等，则分数高的靠前
     * @param that
     * @return
     */
    public int compareTo(Student that) {
        if (this.score == that.score){
            return this.name.compareTo(that.name);
        }
        if (this.score < that.score){
            return 1;
        }else if (this.score > that.score){
            return -1;
        }else{
            return 0;
        }
    }

    @Override
    public String toString() {
        return "Student:" +
                "name='" + this.name + '\'' +
                ", score=" + Integer.toString( this.score );
    }
}
